import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '@/home/Home';
import StudentMain from '@/student/StudentMain';
import Login from '@/home/StudentLogin';
import Admin from '@/home/AdminLogin';
import AdminMain from '@/admin/AdminMain';
import CourseTaskList from '@/admin/arrange/CourseTaskList';
import CourseTable from '@/admin/arrange/CourseTable'
import ChoseRecord from '@/admin/choose/ChoseRecord'
import CourseInfo from '@/admin/choose/CourseInfo'
import AdminScoreManage from '@/admin/score/ScoreManagement'
import axios from "axios";
import StudentList from "@/admin/studentstatus/StudentList";
import ArrangeLesson from "@/admin/arrange/ArrangeLesson.vue";
import TeacherSelect from "@/admin/Teacher/TeacherSelect";
import CultivationSystem from "@/admin/choose/CultivationSystem.vue"

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'Home',
        component: Home,
        meta: {
            noRequireAuth: true
        },
    },
    {
        path: '/student',
        name: 'Student',
        component: StudentMain,
        meta: {
            noRequireAuth: true
        },
    },
    {
        // 学生登录
        path: '/student/login',
        name: 'Login',
        component: Login,
        meta: {
            noRequireAuth: true
        },
    },
    {
        // 管理员登录
        path: '/admin/login',
        name: 'AdminLogin',
        component: Admin,
        meta: {
            noRequireAuth: true
        },
    },
    {
        // admin主界面
        path: '/admin',
        name: 'Admin',
        component: AdminMain,
        children: [
            // 排课管理-课程计划
            {
                path: '/arrangeLesson',
                name: 'ArrangeLesson',
                component: ArrangeLesson
            },
            // 排课管理-课程计划
            {
                path: '/courseTaskList',
                name: 'CourseTaskList',
                component: CourseTaskList
            },
            // 排课管理-查看课表
            {
                path: '/courseTable',
                name: 'CourseTable',
                component: CourseTable
            },
            // 选课管理-选课记录
            {
                path: '/choseRecord',
                name: 'ChoseRecord',
                component: ChoseRecord
            },
            // 选课管理-课程信息管理
            {
                path: '/courseInfo',
                name: 'CourseInfo',
                component: CourseInfo
            },
            // 选课管理-课程信息管理
            {
                path: '/cultivationSystem',
                name: 'CultivationSystem',
                component: CultivationSystem
            },

            {
                path: '/scoreManage',
                name: 'ScoreManage',
                component: AdminScoreManage
            },
            // 学籍管理-所有学生
            {
                path: '/studentlist',
                name: 'StudentList',
                component: StudentList
            },
            // 讲师管理-讲师列表
            {
                path: '/teacherlist',
                name: 'TeacherSelect',
                component: TeacherSelect
            }

        ]
    },

]

const router = new VueRouter({
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    if (!to.matched.some(res => res.meta.noRequireAuth)) {// 判断是否需要登录权限
        if (window.localStorage.getItem('teacher') || window.localStorage.getItem("admin")) {// 判断是否登录
            next()
        } else {
            next({
                path: '/',
                query: {redirect: to.fullPath}
            })
        }
    } else {
        next()
    }
    next()
})

export default router